document.write(`<script src='../../../layer_v2.1/layer/layer.js'></script>`);
document.write(`<script src='../../../js/xm-select.js'></script>`);

// 服务器地址
window.baseUrl = '/api/';
// 测试地址
// window.baseUrl = '/';

// 请求成功后会执行回调
// $(document).ajaxSuccess(function(event,xhr,options){
//     var data=xhr.responseJSON;
//     console.log('xhr>>>>>>>>>>>>', xhr)
//     console.log('data>>>>>>>>>>>>', data)
// });

// 本地地址
// window.baseUrl = '/'

// var userInfo = localStorage.getItem('userInfo')
// var loginTime = localStorage.getItem('loginTime')
// if (!loginTime && !location.href.includes('login')) {
//     window.loc alStorage.clear()
//     window.top.location.href = '/html/login.html'
// }
// if ((+new Date() - loginTime) > 1800 * 1000 && !location.href.includes('login')) {
//     window.localStorage.clear()
//     window.top.location.href = '/html/login.html'
// }
// if (!userInfo && !location.href.includes('login')) {
//     window.top.location.href = '/html/login.html'
// }
// function initBKInfo() {
//     // 根据查询字符串info，来判断显示哪个报考信息
//     const type = getQuery('trainType');
//     switch (type) {
//         case 'education':
//             localStorage.setItem('name', '学生管理/学历提升');
//             break;
//         case 'occupation':
//             localStorage.setItem('name', '学生管理/职业技能');
//             break;
//         case 'title':
//             localStorage.setItem('name', '学生管理/职称评审')
//             break;
//         case 'train':
//             localStorage.setItem('name', '学生管理/执业资格')
//             break;
//     }
// }

// initBKInfo();

function initialSelect(el, data, onChange = () => {}) {
  return xmSelect.render({
    el,
    data,
    on: onChange
  });
}

function getQuery(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split('&');
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split('=');
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  return false;
}

function getId() {
  var date = new Date();
  date = date.getTime();
  return date.toString();
}

function debounce(fn, delay) {
  let handle;
  return function (e) {
    // 取消之前的延时调用
    clearTimeout(handle);
    handle = setTimeout(() => {
      fn(e);
    }, delay);
  };
}

function convertCurrency(money) {
  //汉字的数字
  var cnNums = new Array(
    '零',
    '壹',
    '贰',
    '叁',
    '肆',
    '伍',
    '陆',
    '柒',
    '捌',
    '玖'
  );
  //基本单位
  var cnIntRadice = new Array('', '拾', '佰', '仟');
  //对应整数部分扩展单位
  var cnIntUnits = new Array('', '万', '亿', '兆');
  //对应小数部分单位
  var cnDecUnits = new Array('角', '分', '毫', '厘');
  //整数金额时后面跟的字符
  var cnInteger = '整';
  //整型完以后的单位
  var cnIntLast = '元';
  //最大处理的数字
  var maxNum = 999999999999999.9999;
  //金额整数部分
  var integerNum;
  //金额小数部分
  var decimalNum;
  //输出的中文金额字符串
  var chineseStr = '';
  //分离金额后用的数组，预定义
  var parts;
  if (money == '') {
    return '';
  }
  money = parseFloat(money);
  if (money >= maxNum) {
    //超出最大处理数字
    return '';
  }
  if (money == 0) {
    chineseStr = cnNums[0] + cnIntLast + cnInteger;
    return chineseStr;
  }
  //转换为字符串
  money = money.toString();
  if (money.indexOf('.') == -1) {
    integerNum = money;
    decimalNum = '';
  } else {
    parts = money.split('.');
    integerNum = parts[0];
    decimalNum = parts[1].substr(0, 4);
  }
  //获取整型部分转换
  if (parseInt(integerNum, 10) > 0) {
    var zeroCount = 0;
    var IntLen = integerNum.length;
    for (var i = 0; i < IntLen; i++) {
      var n = integerNum.substr(i, 1);
      var p = IntLen - i - 1;
      var q = p / 4;
      var m = p % 4;
      if (n == '0') {
        zeroCount++;
      } else {
        if (zeroCount > 0) {
          chineseStr += cnNums[0];
        }
        //归零
        zeroCount = 0;
        chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
      }
      if (m == 0 && zeroCount < 4) {
        chineseStr += cnIntUnits[q];
      }
    }
    chineseStr += cnIntLast;
  }
  //小数部分
  if (decimalNum != '') {
    var decLen = decimalNum.length;
    for (var i = 0; i < decLen; i++) {
      var n = decimalNum.substr(i, 1);
      if (n != '0') {
        chineseStr += cnNums[Number(n)] + cnDecUnits[i];
      }
    }
  }
  if (chineseStr == '') {
    chineseStr += cnNums[0] + cnIntLast + cnInteger;
  } else if (decimalNum == '') {
    chineseStr += cnInteger;
  }
  return chineseStr;
}

function openBirthdayMsg() {
  const birthdayMsg = localStorage.getItem('birthdayMsg');
  if (birthdayMsg) {
    layer.open({
      type: 1,
      title: '生日提醒',
      content: `<div class="notice">${birthdayMsg}</div>`,
      shade: 0,
      cancel: function (index) {
        layer.close(index);
        localStorage.removeItem('birthdayMsg');
      },
    });
  }
}

function openMsg() {
  const resolve = localStorage.getItem('resolve');
  const fee = localStorage.getItem('fee');
  const perm = JSON.parse(localStorage.getItem('userInfo')).perm;
  console.log('resolve', resolve);
  console.log('fee', fee);
  if (fee) {
    let msg = '';
    let title = '';
    if (perm === 4 || perm === 5) {
      title = '缴费提醒';
      msg = `小主，您未来30天有${fee}条分期缴费待处理，请尽快处理哦~~`;
    } else {
      title = '审核提醒';
      msg = `小主，您有${fee}条待审核任务,请尽快处理哦~~`;
    }
    layer.open({
      type: 1,
      title,
      content: `<div class="notice">${msg}</div>`,
      shade: 0, //不显示遮罩
      cancel: function (index) {
        layer.close(index);
        localStorage.removeItem('fee');
      },
    });
  }
  if (resolve) {
    layer.open({
      type: 1,
      title: '驳回提醒',
      content: `<div class="notice">小主，您有${resolve}条驳回任务,请尽快处理哦~~</div>`,
      shade: 0, //不显示遮罩
      cancel: function (index) {
        layer.close(index);
        localStorage.removeItem('resolve');
      },
    });
  }

  if (resolve && fee) {
    layer.style(2, {
      width: '360px',
      left: 'calc(100vw - 360px)',
      top: 'calc(100vh - 220px)',
    });
  }

  layer.style(1, {
    width: '360px',
    left: 'calc(100vw - 360px)',
    top: 'calc(100vh - 103px)',
  });
}
